home *** CD-ROM | disk | FTP | other *** search
- Path: crl.crl.com!not-for-mail
- From: gherlein@crl.com (Greg Herlein)
- Newsgroups: comp.lang.c,gnu.gcc.help
- Subject: Re: Casting unsigned short as unsigned int -> Bus error
- Followup-To: comp.lang.c,gnu.gcc.help
- Date: 25 Jan 1996 14:11:41 -0800
- Organization: CRL Network Services (415) 705-6060 [Login: guest]
- Message-ID: <4e8v6t$bd2@crl.crl.com>
- References: <simmons.820857453@rzdspc1> <820879186snz@genesis.demon.co.uk>
- NNTP-Posting-Host: crl.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
- : In article <simmons.820857453@rzdspc1>
- : simmons@rzdspc1.informatik.uni-hamburg.de "Geoffrey Simmons" writes:
-
- : >I have a pointer to a struct with a member declared as unsigned short:
- : >
- : > typedef struct {
- : > ...
- : > unsigned short myshort;
- : > ...
- : > } RecType;
- : >
- : > RecType *MyRec;
- : >
- : >Now when I try to dereference that member, casting it to (unsigned int),
- : >I get a bus error:
- : >
- : > unsigned int myint;
- : >
- : > myint = (unsigned int) MyRec->myshort; /* Bus error! */
- : >
- : >I'm using GCC 2.7.2 on a SparcStation running SunOS 4.1.4. I've made sure
- : >that the pointer points to valid data.
-
- : If that is so then the code is perfectly valid (and the cast is redundant) -
- : your problem is caused somewhere else. Post a minimal compilable program that
- : demonstrates the problem.
-
-
- This sounds to me like a problem I had a while back - though I'm not a
- Sparc guru enough to know for sure. I was reading elements from
- structures like this too, and got bus errors for not reading on 32 bit
- boundaries. Does it work if you read the myshort variable into a
- short *then* cast it to an unsigned int? I'm not sure what the order
- of operations is on the assignment... I would think the dererencing of
- the stucture element poinet would be first, but what do I know?
-
- Good luck!
-
-
- --
- Greg Herlein
- gherlein@crl.com
- http://www.crl.com/www/users/gh/gherlein (under construction, but there!)
- Vallejo, CA
-